

import 'package:bt_tool/basic/bt_color_tool.dart';
import 'package:bt_tool/basic/bt_common_define.dart';
import 'package:bt_tool/basic/bt_theme_color.dart';
import 'package:bt_tool/widget/bt_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_demo/tools/translate/controller/translate_main_controller.dart';
import 'package:flutter_demo/tools/translate/model/translate_content_model.dart';
import 'package:flutter_demo/tools/translate/translate_define.dart';

class TranslateMainItemWidget extends BTStatelessWidget{

  final bool isHead;
  final TranslateContentModel model;
  final TranslateMainController mainController;

  const TranslateMainItemWidget({
    super.key,
    super.routerConfig,
    required this.isHead,
    required this.model,
    required this.mainController,
  });

  @override
  Widget build(BuildContext context) {
    if(isHead){
      return buildHeadWidget();
    }

    List<Widget> widgetList = [

    ];

    for(var headModel in mainController.headModelList){
      var key = headModel.id;
      if (key == TranslateDefine.listStatusKey){
        widgetList.add(
          Container(
            constraints: BoxConstraints.expand(width: headModel.width),
            child: Center(
              child: GestureDetector(
                onTap: (){
                  mainController.changeModelSelectStatus(model);
                },
                child: Image.asset(btPngPath(model.isSel ? "bt/bt_check_box_sel" : "bt/bt_check_box_nor"),width: 20,height: 20,),
              ),
            ),
          )
        );
      }else{
        widgetList.add(
            GestureDetector(
              onDoubleTap: (){
                var type = TranslateMainMenuAction.exportIos;
                if(mainController.projectModel?.translateExportType.value == TranslateDefaultExportType.json.iValue){
                  type = TranslateMainMenuAction.exportJson;
                }
                mainController.doItemMenuAction(model, key, type);
              },
              onSecondaryTapDown: (TapDownDetails details){
                if (key == TranslateDefine.listKeyName){
                  mainController.showKeyMenuView(model,details.globalPosition);
                }else{
                  mainController.showItemMenuView(model,details.globalPosition,key);
                }
              },
              child: Container(
                constraints: BoxConstraints.expand(width: headModel.width),
                alignment: Alignment.center,
                child: SelectableText(model.jsonTool.getString(key),textAlign: TextAlign.center,),
              ),
            )
        );
      }

    }

    return Container(
      color: model.isHadExport == 1 ? BTThemeColor.contentBgColor2 : BTThemeColor.contentBgColor,
      child: Row(
        mainAxisSize: MainAxisSize.max,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: widgetList,
      ),
    );
  }

  Widget buildHeadWidget(){
    List<Widget> widgetList = [];

    for(var headModel in mainController.headModelList){
      var key = headModel.id;
      widgetList.add(
          Container(
            constraints: BoxConstraints.expand(width: headModel.width),
            alignment: Alignment.center,
            child: Text(TranslateDefine.baseLanguageMapReverse[key] ?? ""),
          )
      );
    }

    return Container(
      color: BTThemeColor.contentBgColor,
      child: Row(
        mainAxisSize: MainAxisSize.max,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: widgetList,
      ),
    );
  }

}